
// @ts-nocheck
// 当前时间
export function timeTodayTime(timestamp: any) {
	const date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
	const Y = date.getFullYear() + '-';
	const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	const D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
	const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
	const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
	// s = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds());
	return Y + M + D + h + m;
}

export function timestampToTime(timestamp:string) {
	// timestampToTime(1529111288);
	var date = new Date(timestamp); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
	var Y = date.getFullYear() + '-';
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
	var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
	var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
	var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
	// s = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds());
	return Y + M + D + h + m;
}

// 12月-05日 17:01
export function timeexactDate(exacttime:string) {
	// timestampToTime(2022-12-05 17:01:20);
	let date = new Date(exacttime);
	var M =
		(date.getMonth() + 1 < 10 ?
			"0" + (date.getMonth() + 1) :
			date.getMonth() + 1) + "月";
	var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + "日 ";
	var h =
		(date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
	var m =
		(date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + "";
	return M + D + h + m;
};


// 12-05 17:01
export function timehourDate(hourtime:string) {
	// timestampToTime(2022-12-05 17:01:20);
	let date = new Date(hourtime);
	var M = (date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-";
	var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
	var h =
		(date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
	var m =
		(date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes());
	return M + D + " " + h + m;
};

export function timemonthDate(monthtime:string) {
	// timestampToTime(2022-12-05 17:01:20);
	let date = new Date(monthtime);
	var M =(date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) :date.getMonth() + 1) + "-";
	var D = (date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
	// var h =
	// 	(date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
	// var m =
	// 	(date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) + "";
	return M + D;
};


export function computedTime(old:string) { //传入之前的时间  时间格式为(YY-MM-DD HH:MM:SS)

	var returnText = "";
	var nowDate = new Date().getTime(); //当前时间
	var setDate = new Date(old).getTime();
	var times = Math.floor((nowDate - setDate) / 1000);
	if (times > 60 * 60 * 24 * 365) {
		returnText = Math.floor(times / (60 * 60 * 24 * 365)) + "年前";
	} else if (times > 60 * 60 * 24 * 30) {
		returnText = Math.floor(times / (60 * 60 * 24 * 30)) + "个月前";
	} else if (times > 60 * 60 * 24) {
		returnText = Math.floor(times / (60 * 60 * 24)) + "天前";
	} else if (times > 60 * 60) {
		returnText = Math.floor(times / (60 * 60)) + "小时前";
	} else if (times > 60) {
		returnText = Math.floor(times / (60)) + "分钟前";
	} else if (times > 0) {
		returnText = Math.floor(times / 1) + "秒前";
	} else {
		// returnText = "系统错误,必须传入当前时间之前的数值";
		returnText = "刚刚";
	}

	return returnText;
}

